<!-- xml version="1.0" encoding="utf-8" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<title>Latin Verbs</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<link href="../classics.css" rel="stylesheet" type="text/css">
</head>

<?php

$verbs = array();
function addVerb($verb, $voice, $mood, $tense,
	             $vI, $vThou, $vHe, $vWe, $vYe, $vThey) {
	global $verbs;
	$verbs[$verb][$voice][$mood][$tense] = array('I' => $vI, 'Thou' => $vThou, 'He' => $vHe,
		                                         'We' => $vWe, 'Ye' => $vYe, 'They' => $vThey);
}

addVerb('sum', 'Act.', 'Indic.', 'Pres.', 'sum', 'es', 'est', 'sumus', 'estis', 'sunt');
addVerb('sum', 'Act.', 'Subj.', 'Pres.', 'sim', 'sīs', 'sit', 'sīmus', 'sītis', 'sint');

addVerb('sum', 'Act.', 'Indic.', 'Impf.', 'eram', 'erās', 'erat', 'erāmus', 'erātis', 'erant');
addVerb('sum', 'Act.', 'Subj.', 'Impf.', 'essem', 'essēs', 'esset', 'essēmus', 'essētis', 'essent');

addVerb('sum', 'Act.', 'Indic.', 'Fut.', 'erō', 'eris', 'erit', 'erimus', 'eritis', 'erunt');

addVerb('sum', 'Act.', 'Indic.', 'Perf.', 'fuī', 'fuistī', 'fuit', 'fuimus', 'fuistis', array('fuērunt', 'fuēre'));
addVerb('sum', 'Act.', 'Subj.', 'Perf.', 'fuerim', 'fueris', 'fuerit', 'fuerimus', 'fueritis', 'fuerint');

addVerb('sum', 'Act.', 'Indic.', 'Plup.', 'fueram', 'fuerās', 'fuerat', 'fuerāmus', 'fuerātis', 'fuerant');
addVerb('sum', 'Act.', 'Subj.', 'Plup.', 'fuissem', 'fuissēs', 'fuisset', 'fuissēmus', 'fuissētis', 'fuissent');

addVerb('sum', 'Act.', 'Indic.', 'Fut.Perf.', 'fuerō', 'fueris', 'fuerit', 'fuerimus', 'fueritis', 'fuerint');

$verbs['sum']['Act.']['Imper.']['Pres.']['Thou'] = 'es';
$verbs['sum']['Act.']['Imper.']['Pres.']['Ye'] = 'este';
$verbs['sum']['Act.']['Imper.']['Fut.']['Thou'] = 'estō';
$verbs['sum']['Act.']['Imper.']['Fut.']['Ye'] = 'estōte';
$verbs['sum']['Act.']['Imper.']['Fut.']['He'] = 'estō';
$verbs['sum']['Act.']['Imper.']['Fut.']['They'] = 'suntō';

$verbs['sum']['Act.']['Infi.']['Pres.'] = 'esse';
$verbs['sum']['Act.']['Infi.']['Perf.'] = 'fuisse';
$verbs['sum']['Act.']['Infi.']['Fut.'] = array('futūrus esse', 'fore');

$verbs['sum']['Act.']['Part.']['Fut.'] = 'futūrus';

$verb = array_rand($verbs);
$persons = array('I', 'Thou', 'He', 'We', 'Ye', 'They', 'Other');
$person = $persons[array_rand($persons)];

$n = 2;
if ($person != 'Other') {
	$vtab = "<caption>".$verb." - ".$person."</caption>\n";
	$nVoice = count($verbs[$verb]);
	
	$vtab = $vtab . "<tr><td></td><th colspan=".$nVoice." align=\"center\">Indic.</th>";
	$vtab = $vtab . "<th colspan=".$nVoice." align=\"center\">Subj.</th>";
	$vtab = $vtab . "<th colspan=".$nVoice." align=\"center\">Imper.</th></tr>\n";
	$tmp = '';
	foreach($verbs[$verb] as $voice => $vArray) {
		$tmp = $tmp . "<td align=\"center\">$voice</td>";
	}
	$vtab = $vtab."<tr><td></td>".$tmp.$tmp.$tmp."</tr>\n";
	
	foreach(array('Pres.', 'Impf.', 'Fut.', 'Perf.', 'Plup.', 'Fut.Perf.') as $tense) {		
		$vtab = $vtab . "<tr><th>$tense</th>";
		foreach(array('Indic.', 'Subj.', 'Imper.') as $mood) {
			foreach($verbs[$verb] as $voice => $vArray) {
				$vtab = $vtab . "<td align=\"center\">";
				if (isset($verbs[$verb][$voice][$mood][$tense][$person])) {
					$txt = $verbs[$verb][$voice][$mood][$tense][$person];
					if (is_array($txt)) {
						foreach($txt as $tn) {
							$txts[] = $tn;
							$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\">";
						}
					} else {
						$txts[] = $txt;
						$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\">";
					}
				}
				$vtab = $vtab . "</td>";
			}
		}
		$vtab = $vtab . "</tr>\n";
	}
} else {
	$n = 1;
	$vtab = "<caption>".$verb."</caption>\n";
	$tmp = '';
	foreach($verbs[$verb] as $voice => $vArray) {
		$tmp = $tmp . "<th align=\"center\">$voice</th>";
	}
	foreach(array('Infi.', 'Part.') as $mood) {
		$vtab = $vtab."<tr bgcolor=\"CadetBlue\"><th>$mood</th>$tmp</tr>\n";
		foreach(array('Pres.', 'Fut.', 'Perf.') as $tense) {
			$vtab = $vtab."<tr><th>$tense</th>";
			foreach(array('Act.', 'Pass.') as $voice) {
				$vtab = $vtab."<td align=\"center\">";
				if (isset($verbs[$verb][$voice][$mood][$tense])) {
					$txt = $verbs[$verb][$voice][$mood][$tense];
					if (is_array($txt)) {
						foreach($txt as $tn) {
							$txts[] = $tn;
							$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\">";
						}
					} else {
						$txts[] = $txt;
						$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\">";
					}
				}
				$vtab = $vtab."</td>";
			}
			$vtab = $vtab."</tr>\n";
		}
	}

}
?>

<script type="text/javascript">
function check() 
{

<?php
	for($i = 0, $nall = count($txts); $i < $nall; $i++) {
		print "if (document.n01.text".$i.".value=='".$txts[$i]."')\n{\n";
		print "\tdocument.n01.text".$i.".disabled=true;\n}\n";
	}
?>

}

function newWord() 
{
<?php
	for($i = 0, $nall = count($txts); $i < $nall; $i++) {
		print "document.n01.text".$i.".disabled=false;\n";
 		print "document.n01.text".$i.".value='';\n";
	}
?>
	location.reload();
}
</script>

<body>
<div id="container">
<div id="center">
<form name="n01" action="">
<table align="center">
<?php
	print $vtab;
?>
<tr>
	<td align="center" colspan=<?php print $n; ?>><input name="Check" onclick="check()" value="Check" type="button"></td>
	<td align="center"><input name="New Word" onclick="newWord()" value="New Word" type="button"></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
